package com.scrat.huzhenjie.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.scrat.huzhenjie.model.Backup;
import com.scrat.huzhenjie.model.Recording;
import com.scrat.huzhenjie.service.HuangChengShiService;

/**
 * @author Scrat
 *
 */
@Controller
@RequestMapping(value = "/huangchengshi")
public class HuangChengShiController {
	@Autowired
	private HuangChengShiService huangChengShiService;
	@RequestMapping(value = "/recording/list")
	@ResponseBody
	public List<Recording> getRecordings(	@RequestParam(defaultValue = "-1") int from,
															@RequestParam(defaultValue = "-1") int length,
															HttpServletRequest request){
		return huangChengShiService.getRecordings(from, length,request);
	}
	
	@RequestMapping(value = "/recording/query")
	@ResponseBody
	public List<Recording> getRecordings(	String[] q,
															String[] value,
															@RequestParam(defaultValue = "false") boolean fuzzy,
															@RequestParam(defaultValue = "-1") int from,
															@RequestParam(defaultValue = "-1")int length,
															HttpServletRequest request) {
		return huangChengShiService.getRecordings(q, value, fuzzy, from, length, request);
	}
	
	@RequestMapping(value = "/recording/total")
	@ResponseBody
	public int getRecordingLength(HttpServletRequest request){
		return huangChengShiService.getTotalRecording(request);
	}
	
	@RequestMapping(value = "/recording/count")
	@ResponseBody
	public String getRecordingCount(HttpServletRequest request){
		return huangChengShiService.getRecordingCount(request);
	}
	
	@RequestMapping(value = "/recording/update")
	@ResponseBody
	public boolean updateRecording(	@RequestParam(required = true) int id,
													@RequestParam(required = true) int year,
													@RequestParam(required = true) int month,
													@RequestParam(defaultValue = "") String date,
													@RequestParam(defaultValue = "") String time,
													@RequestParam(defaultValue = "") String weather,
													@RequestParam(defaultValue = "") String mood,
													@RequestParam(defaultValue = "") String address,
													@RequestParam(defaultValue = "") String content,
													@RequestParam(defaultValue = "") String pictureuri,
													@RequestParam(defaultValue = "") String sounduri,
													@RequestParam(defaultValue = "") String other,
													HttpServletRequest request) {
		return huangChengShiService.updateRecording(id, year, month, date, time, weather, mood, address, content, pictureuri, sounduri, other,request);
	}
	
	@RequestMapping(value = "/recording/add")
	@ResponseBody
	public boolean addRecording(		@RequestParam(required = true) int year,
													@RequestParam(required = true) int month,
													@RequestParam(defaultValue = "") String date,
													@RequestParam(defaultValue = "") String time,
													@RequestParam(defaultValue = "") String weather,
													@RequestParam(defaultValue = "") String mood,
													@RequestParam(defaultValue = "") String address,
													@RequestParam(defaultValue = "") String content,
													@RequestParam(defaultValue = "") String pictureuri,
													@RequestParam(defaultValue = "") String sounduri,
													@RequestParam(defaultValue = "") String other,
													HttpServletRequest request) {
		return huangChengShiService.addRecording(year, month, date, time, weather, mood, address, content, pictureuri, sounduri, other,request);
	}
	
	@RequestMapping(value = "/recording/del")
	@ResponseBody
	public boolean deleteRecording(	@RequestParam(defaultValue = "-1") int id,
													HttpServletRequest request) {
		return huangChengShiService.deleteRecording(id,request);
	}
	
	@RequestMapping(value = "/password/reset")
	@ResponseBody
	public boolean resetPassword(	@RequestParam(value = "old_password") String oldPassword,
												@RequestParam(value = "new_password") String newPassword,
												HttpServletRequest request) {
		return huangChengShiService.resetPassword(oldPassword, newPassword, request);
	}
	
	@RequestMapping(value = "/password/forget")
	@ResponseBody
	public boolean forgetPassword(	long imei,
													String tips,
													@RequestParam(value = "new_password") String newPassword,
													HttpServletRequest request) {
		return huangChengShiService.forgetPassword(imei,tips,newPassword,request);
	}
	/*----------------------------------华丽分界线-------------------------------------------------*/
	@RequestMapping(value = "/backup/list")
	@ResponseBody
	public List<Backup> getBackups(HttpServletRequest request) {
		return huangChengShiService.getBackups(request);
	}
	
	@RequestMapping(value = "/backup/add")
	@ResponseBody
	public boolean addBackup(	@RequestParam(defaultValue = "") String name,
											@RequestParam(defaultValue = "") String time,
											@RequestParam(defaultValue = "") String uri,
											HttpServletRequest request){
		return huangChengShiService.addBackup(name, time, uri,request);
	}
	/*----------------------------------华丽分界线-------------------------------------------------*/
	@RequestMapping(value = "/file/upload")
	@ResponseBody
	public String uploadFile(HttpServletRequest request,MultipartFile file){
		return huangChengShiService.uploadFile(request, file);
	}
	
	@RequestMapping(value = "/file/del")
	@ResponseBody
	public boolean deleteFile(HttpServletRequest request,String name) {
		return huangChengShiService.deleteFile(request,name);
	}
	/*----------------------------------华丽分界线-------------------------------------------------*/
	@RequestMapping(value = "/login")
	@ResponseBody
	public boolean login(	long imei,
									String password,
									HttpServletRequest request){
		return huangChengShiService.login(imei, password,request);
	}
	
	@RequestMapping(value = "/register")
	@ResponseBody
	public boolean register(	long imei,
										String password,
										String name,
										int size,
										String tips,
										@RequestParam(defaultValue = "") String email,
										@RequestParam(defaultValue = "") String time,
										@RequestParam(defaultValue = "") String other,
										HttpServletRequest request) {
		return huangChengShiService.register(imei, password, name, size, time, tips, other,email,request);
	}
}
